package com.geekaca.mvc.controller;

import com.geekaca.mvc.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class LoginController {
    @RequestMapping("/login")
    @ResponseBody
    public String login(String username, String password) {
        System.out.println(username);
        System.out.println(password);
        return "ok";
    }

    @RequestMapping("/register")
    @ResponseBody
    public String register(@RequestParam("uname") String username,
                           @RequestParam(required = true ,defaultValue = "666") String password,
                           @RequestParam(defaultValue = "777") String password2
    ) {
        System.out.println(username);
        System.out.println(password);
        System.out.println(password2);
        return "ok";
    }

    // SpringMvc 会自动组装一个对象传入方法
    @RequestMapping("/addUser")
    @ResponseBody
    public String add(User user) {
        System.out.println(user);
        return "ok";
    }

    @RequestMapping("/addUserInfo")
    @ResponseBody
    public String addUserInfo(User user) {
        System.out.println(user);
        System.out.println(user.getAddress());
        return "ok";
    }

    @RequestMapping("/likes")
    @ResponseBody
    public String likes(String[] hobbies) {
        for (int i = 0; i < hobbies.length; i++) {
            System.out.println(hobbies[i]);
        }
        return "ok";
    }

    @RequestMapping("/likes2")
    @ResponseBody
    public String likes2(@RequestParam List<String> hobbies) {
        for (int i = 0; i < hobbies.size(); i++) {
            System.out.println(hobbies.get(i));
        }
        return "ok";
    }
}
